﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Aspect.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Interfaces;
using Twodi.Aspect.Implemented;

namespace Twodi.Implemented
{
    public class Transformed : Base, ITransformationAspect
    {
        public Transformed(Game game)
            : base(game)
        {
            this.TransformationProperties = new DynamicTransformationAspect(this);
        }

        /// <summary>
        /// Verificar se componente contem o ponto.
        /// </summary>
        /// <param name="point">Ponto.</param>
        /// <returns></returns>
        public bool Contains(Vector2 point)
        {
            Vector2 position = Vector2.Transform(point, Inverted);

            float normal = 1f / ScaleProperties.Scale;

            //Sobre componente.
            if (position.X >= 0 && position.X <= SizeProperties.Size.X * normal &&
                position.Y >= 0 && position.Y <= SizeProperties.Size.Y * normal)
            {
                return true;
            }

            return false;
        }

        public virtual Matrix Transformation
        {
            get
            {
                return this.TransformationProperties.Transformation;
            }
        }

        public Matrix Inverted
        {
            get
            {
                return Matrix.Invert(this.Transformation);
            }
        }

        public ITransformation TransformationProperties
        {
            get;
            set;
        }
    }
}
